package com.itheima.dao;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @author huyoufu <https://github.com/huyoufu>
 * @TIME 2020-08-09 09:00
 * @description
 */
@Repository
public class AccountDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    public void sub(String from, double money) {
        String sql="update account set money=money-? where name=?";

        //使用jdbctemplate执行sql语句
        jdbcTemplate.update(sql,money,from);

    }

    public void add(String to, double money) {
        String sql="update account set money=money+? where name=?";
        jdbcTemplate.update(sql,money,to);
    }
}
